package com.heaven.back.pojo;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * The type Player.
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Player {
    //可序列化的接口
    private int id;
    private String name;
    private String password;
    private double weight = 0.0;
    private double weighmax = 10.0;
    private int islogin = 0;
    private List<Item> _items = new ArrayList<>();
    private String items = "";
    private String currentRoom = "森林中心";

    /**
     * Add item boolean.
     *
     * @param item the item
     * @return the boolean
     */
    public boolean add_item(Item item) {
        if (weight + item.getWeight() > weighmax) {
            return false;
        }
        weight += item.getWeight();
        _items.add(item);
        //同步数据库和数组数据
        items = JSONObject.toJSONString(_items);
        return true;
    }//添加物品，并减少重量

    /**
     * Remove item.
     *
     * @param i the
     */
    public void remove_item(int i) {
        weight -= _items.get(i).getWeight();
        _items.remove(i);
        items = JSONObject.toJSONString(_items);
    }//移除物品，放置在地图上，同时减少重量


    /**
     * Is login boolean.
     *
     * @return the boolean
     */
    public Boolean isLogin() {
        if (islogin == 0) return false;
        return true;
    }
}
